package cn.dansj.common.utils.transfer;

import java.util.function.Supplier;

public abstract class AssertUtils {
    public static void notNull(Object object, String message) {
        if (Verification.checkNull(object)) throw new IllegalArgumentException(message);
    }

    public static <T> void notNull(Object object, Supplier<T> supplier) {
        state(Verification.checkNotNull(object), supplier);
    }

    public static void state(boolean expression, String message) {
        if (!expression) throw new IllegalStateException(message);
    }

    public static <T> void state(boolean expression, Supplier<T> supplier) {
        if (!expression) {
            T t = supplier.get();
            if (t == null) throw new AssertionError();
            if (t instanceof Throwable) throw new AssertionError(t);
            if (t instanceof String) throw new AssertionError(t);
        }
    }
}
